import dm18n from "@/dm18n"

export default {
    data(){
        return {
            dm18n
        }
    },
    computed: {
        message(){
            return this.dm18n.messages[this.locale];
        },
        locale(){
            return this.dm18n.locale
        }
    },
    methods: {
        setLang(lang){
            this.dm18n.locale = lang
        },
        setLocaleMessage(lang, message){
            let messages = this.dm18n.messages[lang];
            if(messages){
                Object.assign(this.dm18n.messages[lang], message);
            }else{
                this.dm18n.messages[lang] = message;
            }
        },
        $t(path){
            try{
                return eval(`this.message.${path}`) || path;
            }catch(e){
                return path;
            }
        }
    }
}